<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SwtMachineGood extends Model
{
    use HasFactory;

    use HasDateTimeFormatter;

    protected $guarded = [];

    protected $appends = ['goods_name_price'];


    public function goods()
    {
        return $this->hasOne(SwtGood::class,'id','goods_id');
    }

    public function getGoodsNamePriceAttribute(){
        $goods_info = SwtGood::where('id', $this->goods_id) -> first();

        return $this->attributes['goods_name_price'] = "¥".($this->sell_price/100)."--".$goods_info->goods_name;
    }
}
